package org.jtao.gbsubject.domain;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
import cn.afterturn.easypoi.excel.annotation.ExcelEntity;
import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
import io.swagger.annotations.ApiModel;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import java.util.Objects;

/**
 * 专业实体
 */
@ApiModel(description = "专业实体")
@Entity
@Table(name = "subject")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Subject implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Excel(name = "专业名称")
    @Column(name = "name")
    private String name;

    @Excel(name = "专业代码")
    @Column(name = "code")
    private String code;

    @Excel(name = "在校生数")
    @Column(name = "student_sum")
    private Integer studentSum;

    @ExcelEntity(name = "专业类")
    @ManyToOne
    private SubjectClazz subjectClazz;

    @ExcelCollection(name = "所在学院")
    @ManyToMany
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    @JoinTable(name = "subject_college",
        joinColumns = @JoinColumn(name = "subjects_id", referencedColumnName = "id"),
        inverseJoinColumns = @JoinColumn(name = "colleges_id", referencedColumnName = "id"))
    private Set<College> colleges = new HashSet<>();

    // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public Subject name(String name) {
        this.name = name;
        return this;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public Subject code(String code) {
        this.code = code;
        return this;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Integer getStudentSum() {
        return studentSum;
    }

    public Subject studentSum(Integer studentSum) {
        this.studentSum = studentSum;
        return this;
    }

    public void setStudentSum(Integer studentSum) {
        this.studentSum = studentSum;
    }

    public SubjectClazz getSubjectClazz() {
        return subjectClazz;
    }

    public Subject subjectClazz(SubjectClazz subjectClazz) {
        this.subjectClazz = subjectClazz;
        return this;
    }

    public void setSubjectClazz(SubjectClazz subjectClazz) {
        this.subjectClazz = subjectClazz;
    }

    public Set<College> getColleges() {
        return colleges;
    }

    public Subject colleges(Set<College> colleges) {
        this.colleges = colleges;
        return this;
    }

    public Subject addCollege(College college) {
        this.colleges.add(college);
        return this;
    }

    public Subject removeCollege(College college) {
        this.colleges.remove(college);
        return this;
    }

    public void setColleges(Set<College> colleges) {
        this.colleges = colleges;
    }
    // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Subject subject = (Subject) o;
        if (subject.getId() == null || getId() == null) {
            return false;
        }
        return Objects.equals(getId(), subject.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getId());
    }

    @Override
    public String toString() {
        return "Subject{" +
            "id=" + getId() +
            ", name='" + getName() + "'" +
            ", code=" + getCode() +
            ", studentSum=" + getStudentSum() +
            "}";
    }
}
